﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using System;


namespace Safover.LidarCollector.Extensions
{
    public class TimeUtils
    {
        public static long BeiJingTimeToUtcTimestamp(DateTime localTime)
        {
            var dto = (DateTimeOffset)localTime;
            long timeStamp = dto.ToUnixTimeMilliseconds();

            return timeStamp;
        }

        public static DateTime BeiJingTime2UtcTime(DateTime localTime)
        {
            return localTime.ToUniversalTime();
        }

        public static DateTime UtcTimeToBeiJingTime(DateTime utcDateTime)
        {
            return ((DateTimeOffset)utcDateTime).LocalDateTime;
        }

        public static DateTime Timestamp2UtcTime(long timestamp) 
        {
            DateTimeOffset dto = DateTimeOffset.FromUnixTimeMilliseconds(timestamp);

            return dto.UtcDateTime;
        }

        public static DateTime UtcTimestamp2BeiJingDateTime(long timestamp)
        {
            DateTimeOffset dto = DateTimeOffset.FromUnixTimeMilliseconds(timestamp);

            return dto.LocalDateTime;
        }
    }
}
